import { userProfilesAPI } from "@/request/api";

export default {
  namespaced: true,
  state: {
    // 购物车数量
    cartTotal: 10,
    // 用户信息
    userInfo: {
      headImg: require("../../assets/img/service.848ec511.png"),
      nickName: "***",
      coin: "--",
    },
  },

  mutations: {
    updateUserInfo(state, payload) {
      // console.log("用户数据渲染");
      state.userInfo = payload.userInfo;
      state.cartTotal = payload.cartTotal;
    },
    initUserInfo(state, payload) {
      (state.cartTotal = 0),
        (state.userInfo = {
          headImg: require("../../assets/img/service.848ec511.png"),
          nickName: "***",
          coin: "--",
        });
    },
  },

  actions: {
    async asyncChangeUserInfo(context) {
      let res = await userProfilesAPI();
      // console.log("userProfilesAPI", res);
      context.commit("updateUserInfo", res.data);
    },
  },
};
